package api;

import utils.CommUtils;
import utils.HttpUtils;

import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;

/**
 * 银行卡核验API接口
 */
public class BankApi extends AccessToken {
    private final static String bankElem2URI = "/aip/check/v1/bank/elem2";
    private final static String bankElem3URI = "/aip/check/v1/bank/elem3";
    private final static String bankElem4URI = "/aip/check/v1/bank/elem4";
    private final static String bankElem5URI = "/aip/check/v1/bank/elem5";

    /**
     * 1.银行卡二要素核验
     */
    public static void bankElem2(String _BizNo, String idName, String bankCard) {
        Map<String, Object> paramsMap = new TreeMap<>();
        paramsMap.put("appId", appId);
        paramsMap.put("idName", idName);
        paramsMap.put("bankCard", bankCard);
        paramsMap.put("_BizNo", _BizNo);
        paramsMap.put("sign", CommUtils.sign(paramsMap, secretKey));
        String res = HttpUtils.doPostJSON(host, bankElem2URI, getCachedAccessToken(), paramsMap);
        System.out.println("银行卡二要素核验-- >> bankElem2:" + res);
    }

    /**
     * 1.银行卡三要素核验
     */
    public static void bankElem3(String _BizNo, String idName, String idNumber, String bankCard) {
        Map<String, Object> paramsMap = new TreeMap<>();
        paramsMap.put("appId", appId);
        paramsMap.put("idName", idName);
        paramsMap.put("idNumber", idNumber);
        paramsMap.put("bankCard", bankCard);
        paramsMap.put("_BizNo", _BizNo);
        paramsMap.put("sign", CommUtils.sign(paramsMap, secretKey));
        String res = HttpUtils.doPostJSON(host, bankElem3URI, getCachedAccessToken(), paramsMap);
        System.out.println("银行卡三要素核验-- >> bankElem3:" + res);
    }

    /**
     * 2.银行卡四要素核验
     */
    public static void bankElem4(String _BizNo, String idName, String idNumber, String bankCard, String phoneNumber) {
        Map<String, Object> paramsMap = new TreeMap<>();
        paramsMap.put("appId", appId);
        paramsMap.put("idName", idName);
        paramsMap.put("idNumber", idNumber);
        paramsMap.put("bankCard", bankCard);
        paramsMap.put("phoneNumber", phoneNumber);
        paramsMap.put("_BizNo", _BizNo);
        paramsMap.put("sign", CommUtils.sign(paramsMap, secretKey));
        String res = HttpUtils.doPostJSON(host, bankElem4URI, getCachedAccessToken(), paramsMap);
        System.out.println("银行卡四要素核验-- >> bankElem3:" + res);
    }

    /**
     * 3.银行卡五要素核验
     */
    public static void bankElem5(String _BizNo, String idName, String idNumber, String bankCard, String phoneNumber, String bankCardType) {
        Map<String, Object> paramsMap = new TreeMap<>();
        paramsMap.put("appId", appId);
        paramsMap.put("idName", idName);
        paramsMap.put("idNumber", idNumber);
        paramsMap.put("bankCard", bankCard);
        paramsMap.put("phoneNumber", phoneNumber);
        paramsMap.put("bankCardType", bankCardType); //可选取值 1：I类，2：II类 3：III类
        paramsMap.put("_BizNo", _BizNo);
        paramsMap.put("sign", CommUtils.sign(paramsMap, secretKey));
        String res = HttpUtils.doPostJSON(host, bankElem5URI, getCachedAccessToken(), paramsMap);
        System.out.println("银行卡五要素核验-- >> bankElem5:" + res);
    }

    public static void main(String[] args) {
        //1.银行卡二要素核验
        bankElem2(UUID.randomUUID().toString(), "张三", "440804xxxxxxxxxx");
        //2.银行卡三要素核验
        bankElem3(UUID.randomUUID().toString(), "张三", "44080418800607012X", "440804xxxxxxxxxx");
        //3.银行卡四要素核验
        bankElem4(UUID.randomUUID().toString(), "张三", "44080418800607012X", "440804xxxxxxxxxx", "15012171720");
        //4.银行卡五要素核验
        bankElem5(UUID.randomUUID().toString(), "张三", "44080418800607012X", "440804xxxxxxxxxx", "15012171720", "1");
    }
}
